package cuppics;

import org.junit.Test;

public class Prj17 {

	/**
	 * If the numbers 1 to 5 are written out in words: one, two, three, four,
	 * five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
	 * 
	 * If all the numbers from 1 to 1000 (one thousand) inclusive were written
	 * out in words, how many letters would be used?
	 */
	@Test
	public void test() {
		int letters = 0;
		int Unit[] = { 0, 3, 3, 5, 4, 4, 3, 5, 5, 4 };
		int Tens[] = { 0, 0, 6, 6, 5, 5, 5, 7, 6, 6 };
		int Tensone[] = { 3, 6, 6, 8, 8, 7, 7, 9, 8, 8 };
		for (int i = 1; i < 1000; i++) {
			if (i / 10 % 10 == 1) {
				letters = letters + Tensone[i % 10];
			} else {
				letters = letters + Unit[i % 10];
				letters += Tens[i / 10 % 10];
			}
			if (i / 100 > 0) {
				if (i % 100 == 0) {
					letters += Unit[i / 100] + 7;
				} else {
					letters += Unit[i / 100] + 10;
				}
			}
		}
		letters += 11;

		System.out.println(letters);
	}

}
